<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

$api = app('Dingo\Api\Routing\Router');

$api->version('v1', [
    'namespace' => 'App\Http\Controllers\Api',
], function ($api) {
    // 登录接口节流
    $api->group([
        'middleware' => 'api.throttle',
        'limit' => config('api.rate_limits.sign.limit'),
        'expires' => config('api.rate_limits.sign.expires'),
    ], function ($api) {
        // 登录认证接口
        $api->post('authorizations', 'AuthorizationsController@store')
            ->name('api.authorizations.store');
    });

    // 普通接口节流
    $api->group([
        'middleware' => 'api.throttle',
        'limit' => config('api.rate_limits.access.limit'),
        'expires' => config('api.rate_limits.access.expires'),
    ], function ($api) {

        $api->post('products/import', 'ProductsController@bulkImport')
            ->name('api.products.import');


        // 需要认证的接口
        $api->group([
            'middleware' => 'api.auth'
        ], function ($api) {

            $api->get('brands', 'BrandsController@index')
                ->name('api.brands.index');

            $api->get('products', 'ProductsController@index')
                ->name('api.products.index');

            $api->post('user/products', 'UserProductsController@store')
                ->name('api.user.products.store');

            // 更新用户信息
            $api->put('user', 'UsersController@update')
                ->name('api.user.update');


        });
    });
});

